#!/bin/bash
# 根据规则生成 triple 数据集
# timestamp=$(date +%s)

# dataset_name=('conll04' 'SciERC' 'semval-RE')
# dataset_name=('conll04')
# dataset_name=('conll04' 'SciERC')
# dataset_name=('SciERC')
# dataset_name=('SciERC')
dataset_name=('conll04')
# dataset_name=('semval-RE')

seeds=(100)
AUG_TIMES=(1)
# few_shot_nums=(50 100 150)
few_shot_nums=(0)
is_few_shot=1
is_ft_generator=0


# rules=(
#     ''
#     # 'add_triple'
#     # 'add_same_type_triple'
#     # 'remove_triple'
#     # 'replace_same_type_entity'
#     # 'swap_triple'
#     'origin'
#     "add_triple remove_triple replace_same_type_entity swap_triple"
#     # "add_triple"
# )


settings=(
    # "empty 0"
    "origin 0"
    "all 0"
    # "all 1"
)

for few_shot_num in "${few_shot_nums[@]}"; do
    timestamp=$(date +"%m%d%H%M%S")
    # timestamp='09_18_16_31_11'
    for t in "${AUG_TIMES[@]}"; do
        for seed in "${seeds[@]}"; do
            echo "Executing script for seed: $seed"
            for dataset in "${dataset_name[@]}"; do
                if [ "$dataset" = "semval-RE" ]; then
                    valid_task="RE"
                else
                    valid_task="RE_STRICT"
                fi
                for setting in "${settings[@]}"; do
                    # 将设置拆分为 rule 和 is_ft_generator
                    read -r rule is_ft_generator <<<"$setting"

                    # 对于 "all" 规则，根据数据集设置完整的规则字符串
                    if [ "$rule" = "all" ]; then
                        if [ "$dataset" = "semval-RE" ]; then
                            rule="add_triple add_same_type_triple origin"
                        else
                            rule="add_triple origin remove_triple replace_same_type_entity swap_triple"
                        fi
                    fi

                    # 处理空规则的情况
                    if [ "$rule" = "empty" ]; then
                        rule=""
                    fi

                    echo 'rule:' $rule

                    # 只有在 rule 非空时执行 gen4da_md_abalation.sh
                    if [ -n "$rule" ]; then
                        echo "Executing gen4da_llm.sh"
                        # bash ./gen4da_md_ablation.sh "$dataset" "$timestamp" "$seed" "$is_ft_generator" "$t" "$few_shot_num" "$rule"
                        bash ./gen4da_llm.sh "$dataset" "$timestamp" "$t" "$few_shot_num" "$rule"
                    else
                        echo "Skipping gen4da_llm.sh due to empty rule"
                    fi

                    # 执行 train4hf.sh
                    bash train4data_aug.sh "$dataset" "$timestamp" "$seed" "$valid_task" "$t" "$few_shot_num" "$rule"
                done
            done
        done
    done
done
